package com.example.qiandao.repository;

import com.example.qiandao.entity.User;
import com.example.qiandao.entity.Clazz;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface UserRepository extends JpaRepository<User, Long> {

    // 新增方法：根据 clazzId 查询用户
    @Query("SELECT u FROM User u JOIN u.classes c WHERE c.id = :clazzId AND u.role = :role")
    List<User> findUsersByClazzIdAndRole(@Param("clazzId") Long clazzId, @Param("role") int role);

    // 新增方法：根据微信 openid 查询用户
    @Query("SELECT u FROM User u WHERE u.openid = :openid")
    User findByOpenid(@Param("openid") String openid);

    List<User> findByClassId(Long classId);
}
